package figure8.GUI;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Locale;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JToggleButton;
import javax.swing.border.BevelBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import figure8.Controller;
import figure8.Track;
import figure8.WAVTrack;
import figure8.GUI.EffectWindow.Effect;

public class NoiseGatePanel extends EffectPanel {

	final JKnob noiseGateKnob;
	final JKnob gainKnob;
	final EffectPanel effPan = this;
	final EffectWindow effWindow;
	Color BG = new Color(185, 134, 83);
	Color FG = new Color(51,0,0);

	public NoiseGatePanel(EffectWindow effWin){ this(effWin, Effect.PRE_AMP, 0.3, 0.8); }

	public NoiseGatePanel(EffectWindow effWin, Effect effType, double noiseGateSet, double gainSet){
		super(effType, effWin);
		this.effWindow = effWin;
		
		JPanel background = new JPanel();
		background.setBackground(BG);
		background.setForeground(FG);

		JPanel titlePanel = new JPanel();
		titlePanel.setLayout(new GridBagLayout());
		titlePanel.setBackground(BG);
		titlePanel.setForeground(FG);
		
		//DELETE
		JLabel del = new JLabel("x");
		del.setForeground(FG);
		del.setFont(new Font(Font.SERIF, Font.BOLD, 15));

		del.addMouseListener(new MouseListener() {
			public void mouseClicked(MouseEvent arg0) {	}
			public void mouseEntered(MouseEvent arg0) {	}
			public void mouseExited(MouseEvent arg0) { }
			public void mouseReleased(MouseEvent arg0) { }
			public void mousePressed(MouseEvent arg0) {
				effWindow.effPanelDeletion(effPan);
			}
		});
		
		//TITLE
		JLabel title = 
		new JLabel("     " + "PRE AMP", JLabel.CENTER);
		title.setFont(new Font(Font.SERIF, Font.BOLD, 20));
		title.setPreferredSize(new Dimension(220, 20));
		title.setForeground(FG);
		
		GridBagConstraints a = new GridBagConstraints();
		a.fill = GridBagConstraints.BOTH;
		a.anchor = a.CENTER;
		a.gridwidth = GridBagConstraints.RELATIVE;
		titlePanel.add(title, a);
		a.anchor = a.FIRST_LINE_END;
		a.ipadx = 30;
		a.gridwidth = GridBagConstraints.REMAINDER;
		titlePanel.add(del, a);
		
		JPanel knobs = new JPanel();
		knobs.setLayout(new GridLayout(1,2));
		
		//Noise Gate Column
		JPanel noiseGatePanel = new JPanel();
		noiseGatePanel.setLayout(new BoxLayout(noiseGatePanel, BoxLayout.Y_AXIS));
		JLabel noiseGate = new JLabel("Gate");
		noiseGate.setFont(new Font(Font.SERIF,Font.BOLD, 12));
		noiseGate.setForeground(FG);
		
		noiseGateKnob = new JKnob(noiseGateSet, Color.BLACK, Color.WHITE);
		noiseGatePanel.setPreferredSize(new Dimension(75, 80));
		noiseGatePanel.add(noiseGate, BorderLayout.CENTER);
		noiseGatePanel.add(noiseGateKnob, BorderLayout.CENTER);
		noiseGatePanel.setBackground(BG);
		
		//Pre Amp Gain Column
		JPanel gainPanel = new JPanel();
		gainPanel.setLayout(new BoxLayout(gainPanel, BoxLayout.Y_AXIS));
		JLabel gain = new JLabel("Gain");
		gain.setFont(new Font(Font.SERIF,Font.BOLD, 12));
		gain.setForeground(FG);
		
		gainKnob = new JKnob(gainSet, Color.BLACK, Color.WHITE);
		gainPanel.setPreferredSize(new Dimension(75, 80));
		gainPanel.add(gain, BorderLayout.CENTER);
		gainPanel.add(gainKnob, BorderLayout.CENTER);
		gainPanel.setBackground(BG);
		
		
		knobs.add(noiseGatePanel);
		knobs.add(gainPanel);
		
		background.add(titlePanel);
		
		background.add(knobs);

		this.add(background);
	}
	
	public double[] getSettings() {
		double[] settings = {noiseGateKnob.getPercent(), gainKnob.getPercent()};
		return settings;
	}

}
